﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
using Worktool.CODE_Chris.SQL_DATA;

namespace Worktool
{
    public partial class Serials_log : Form
    {
        private SQL sql;
        private SqlDataAdapter sqlDataAdapter1 = new SqlDataAdapter();
        private BindingSource bindingSource1 = new BindingSource();
        private DataTable dataTable1;
        private String select1;

        public Serials_log()
        {
            InitializeComponent();
            init();
        }

        private void init()
        {
            sql = new SQL();
            populateSQLStrings();

            getData1();
        }

        #region Methoden für gridView1 (Hauptmaske)
        public void getData1()
        {
            try
            {
                dataGridView1.DataSource = bindingSource1;

                sqlDataAdapter1 = new SqlDataAdapter(select1, Login.connection);

                SqlCommandBuilder commandBuilder = new SqlCommandBuilder(sqlDataAdapter1);

                // Populate a new data table and bind it to the BindingSource.
                dataTable1 = new DataTable();
                dataTable1.Locale = System.Globalization.CultureInfo.InvariantCulture;
                sqlDataAdapter1.Fill(dataTable1);
                bindingSource1.DataSource = dataTable1;

                //dataGridView1.AutoGenerateColumns = false;
            }
            catch (Exception e)
            {
                sql.log("FEHLER", e, this.ToString() + ":" + System.Reflection.MethodBase.GetCurrentMethod().Name);
            }
        }
        #endregion

        #region SQL-Befehle als Strings
        private void populateSQLStrings()
        {
            select1 = "SELECT ID, Artikel_ID, serialNumber, Manufacturer, Model, Description, serialDate, serialUser FROM tbl_log_vw_lbl_Serials";
        }
        #endregion

        private void Serials_log_Load(object sender, EventArgs e)
        {
            typeof(DataGridView).InvokeMember("DoubleBuffered", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty, null, dataGridView1, new object[] { true });
        }

    }
}
